package com.leoandroid.tool.toolsbox.new

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
import com.leoandroid.tool.toolsbox.adapter.DriverAdapter
import com.leoandroid.tool.toolsbox.bean.DriverBean
import com.leoandroid.tool.toolsbox.largeread.databinding.ActivityDriverQuestionBinding
import com.leoandroid.tool.toolsbox.net.NetCallBack
import com.leoandroid.tool.toolsbox.net.NetRequest
import org.json.JSONObject

class DriverQuestionActivity:AppCompatActivity() {

    var bindF : ActivityDriverQuestionBinding?=null
    val binding get() = bindF!!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        bindF = ActivityDriverQuestionBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.includeTitle.backIv.setOnClickListener {
            finish()
        }
        binding.includeTitle.titleTv.text = "驾照题库"
        val url = "http://v.juhe.cn/jztk/query?subject=1&model=c1&key=34f9c85c30ac87ee569b060c9b82ab8b&testType=rand"
        NetRequest.asyncGet(url,object:NetCallBack{
            override fun onFailure(code: Int, e: Throwable?) {

            }

            override fun onSuccess(json: JSONObject?) {
                Log.d("ppppppp","解析前数据》》"+json)
                val fromgson = Gson().fromJson(json.toString(),DriverBean::class.java)
                Log.d("ppppppp","解析前数据后》》"+fromgson)
                runOnUiThread {
                    val adapter = DriverAdapter(this@DriverQuestionActivity,fromgson.result)
                    binding.recycleview.layoutManager = LinearLayoutManager(this@DriverQuestionActivity)
                    binding.recycleview.adapter = adapter
                }
            }

        })
    }
}